//
//  LJHGuideViewController.m
//  HEARME
//
//  Created by mac on 16/2/27.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LJHGuideViewController.h"

@interface LJHGuideViewController ()

@property (nonatomic, retain)UIButton *pushBtn;
@property (nonatomic, retain)UILabel *contenLabel;
@property (nonatomic, assign)NSInteger number;
@property (nonatomic, retain)NSTimer *time;

@end

@implementation LJHGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *bgImageV = [[UIImageView alloc]initWithFrame:self.view.bounds];
    
    bgImageV.image = [UIImage imageNamed:@"morning"];
    
    [self.view addSubview:bgImageV];
    bgImageV.alpha = 1;
    
    CGRect textFrame = self.view.bounds;
    
    textFrame.origin.x = 40;
    
    textFrame.origin.y = 200;
    
    textFrame.size.width = self.view.bounds.size.width-80;
    
    textFrame.size.height = 300;
    
    self.contenLabel = [[UILabel alloc]initWithFrame:textFrame];
    
    self.contenLabel.backgroundColor = [UIColor clearColor];
    
    self.contenLabel.textColor = [UIColor redColor];
    
    self.contenLabel.numberOfLines = 0;
    
    
    
    [self.view addSubview:self.contenLabel];
    
    
    
    self.pushBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    CGRect btnFrame = self.view.bounds;
    
    btnFrame.origin.x = 20;
    
    btnFrame.origin.y = self.contenLabel.frame.origin.y+self.contenLabel.frame.size.height;
    
    btnFrame.size.width = self.view.bounds.size.width-40;
    
    btnFrame.size.height = 50;
    
    self.pushBtn.frame = btnFrame;
    

    
    [self.pushBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [self.pushBtn setTitle:@"Welcome HEARME" forState:UIControlStateNormal];
    
    self.pushBtn.alpha = 0;
    
    [self.view addSubview:self.pushBtn];
    
    [self.pushBtn addTarget:self action:@selector(disappear) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *jumpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    jumpBtn.frame = CGRectMake(self.view.bounds.size.width-80, 100, 40, 20);
    
    [jumpBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [jumpBtn setTitle:@"跳过" forState:UIControlStateNormal];
    
    jumpBtn.backgroundColor = [UIColor colorWithWhite:0.667 alpha:0.720];
    
    [jumpBtn addTarget:self action:@selector(disappear) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:jumpBtn];
    
    
    
    
    
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [UIView animateWithDuration:4 animations:^{
            UIImage *image = [UIImage imageNamed:@"afternoon"];

            bgImageV.image = image;
//            bgImageV.alpha = 1;
//            bgImageV.alpha = 0;
            
        }];
        
    });
    

    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [UIView animateWithDuration:3 animations:^{
            
            bgImageV.alpha = 0;
            
        }];
        
    });
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [UIView animateWithDuration:2 animations:^{
        
            UIImage *image = [UIImage imageNamed:@"evening"];
            
//            bgImageV.image = [image boxblurImageWithBlur:0.6];
            UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
            
            UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
            
            [visualEffectView setFrame:bgImageV.bounds];
            
            [bgImageV addSubview:visualEffectView];
            [visualEffectView release];
            bgImageV.image = image;
            bgImageV.alpha = 1;
            
            
        }];
        
    });
    

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        self.time = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(inputText) userInfo:nil repeats:YES];
        
    });
    
    
}


- (void)inputText {
    
    NSRange range1 = NSMakeRange(0,_number);
    
    NSString *string = @"  HEARME，是不容错过的听的神器！内容全、极方便、不耗流量不花钱、没有信号也能听。无论在上下班路上、在公交地铁、在开车、在排队、在旅途，还是在扫地洗碗、在蹲厕所、在陪宝宝、在健身…无论你想听新闻、音乐、有声小说，还是郭德纲相声、财经郎眼、飞鱼秀、电台电视台节目，或者是BBC、CNN、美国之音、余世维讲座，以及个性化的电台内容…HEARME都能让你：随时随地，听我想听！";
    
    NSString * string1 = [string substringWithRange:range1];//截取范围类的字符串
    
    _number++;
    
    [self.contenLabel setText:string1];
    
    if (_number == string.length) {
        
        [self.time invalidate];
        
        [UIView animateWithDuration:0.5 animations:^{
            
            self.pushBtn.alpha = 1;
            
        }];
    }
    
    
    
    
}


- (void)disappear {
    
    [self.time invalidate];
    
    [[NSUserDefaults standardUserDefaults]setObject:@"yes" forKey:@"LeadInPages"];
    
    [[NSNotificationCenter defaultCenter]postNotificationName:@"LeadInPages" object:nil];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
